#!/bin/sh

funarr=("+" "-" "*" "/") 
kharr=("(" ")")

function loop2Compute() {
	num1=$1
	num2=$2
	num3=$3
	num4=$4
	for op1 in ${funarr[@]}
	do
		for op2 in ${funarr[@]}
		do
			for op3 in ${funarr[@]}
			do
			jisuan="$num1${op1}$num2${op2}$num3${op3}$num4"
#res=$(echo "$jisuan" | bc)
			res=$(($jisuan))
			echo "$jisuan = $res"

			jisuan="($num1${op1}$num2)${op2}$num3${op3}$num4"
			res=$(($jisuan))
			echo "$jisuan = $res"

			jisuan="$num1${op1}($num2${op2}$num3)${op3}$num4"
			res=$(($jisuan))
			echo "$jisuan = $res"

			jisuan="$num1${op1}$num2${op2}($num3${op3}$num4)"
			res=$(($jisuan))
			echo "$jisuan = $res"

			jisuan="($num1${op1}$num2)${op2}($num3${op3}$num4)"
			res=$(($jisuan))
			echo "$jisuan = $res"

			jisuan="($num1${op1}$num2${op2}$num3)${op3}$num4"
			res=$(($jisuan))
			echo "$jisuan = $res"

			jisuan="$num1${op1}($num2${op2}$num3${op3}$num4)"
			res=$(($jisuan))
			echo "$jisuan = $res"
			done
		done
	done
}

loop2Compute 4 2 8 6
exit 0

numarr=("4" "2" "8" "6")
for n1 in ${numarr[@]}
do
	for n2 in ${numarr[@]}
	do
		if [ "$n1" = "$n2" ]
		then
			continue
		fi
		for n3 in ${numarr[@]}
		do
			if [ "$n1" = "$n3" -o "$n2" = "$n3" ]
			then
				continue
			fi
			for n4 in ${numarr[@]}
			do
				if [ "$n1" = "$n4" -o "$n2" = "$n4" -o "$n3" = "$n4" ]
				then
					continue
				fi
				echo "$n1 $n2 $n3 $n4"
				loop2Compute $n1 $n2 $n3 $n4 |grep -E "= 24$"
			done
		done
	done
done
